package com.sunfeng.chap4.test3;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @description:
 * @author: 孙 峰
 * @time: 2020/11/9 14:33
 */
public class Server {
    public static void main(String[] args) {
        try {
            byte[] bytes = new byte[1024];
            ServerSocket serverSocket = new ServerSocket(8088);
            System.out.println("server accept阻塞开始=" + System.currentTimeMillis());
            Socket socket = serverSocket.accept();
            System.out.println("server accept阻塞结束=" + System.currentTimeMillis());
            InputStream inputStream = socket.getInputStream();
            System.out.println("server read阻塞开始=" + System.currentTimeMillis());
            // 客户端没有发送数据  就会一直阻塞在这里
            int read = inputStream.read(bytes);
            System.out.println("server read阻塞结束=" + System.currentTimeMillis());
            inputStream.close();
            serverSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
